﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class QualificationCategory : IEquatable<QualificationCategory>
    {
        public void ImportList(List<Classes.QualificationCategory> QualCatList)
        {
            var mdb = new MedregDBDataContext();
            var ListQualCat = new List<QualificationCategory>();
            foreach (var qualcat in QualCatList)
            {
                QualificationCategory quatcal1 = new QualificationCategory() { ID = qualcat.ID, Name = qualcat.Name };
                QualificationCategory query;

                if (mdb.QualificationCategory.LongCount() == 0)
                {
                    mdb.QualificationCategory.InsertOnSubmit(quatcal1);
                }
                else
                {
                    try
                    {
                        query = mdb.QualificationCategory.Single(l => l.ID == quatcal1.ID);
                        query.Name = quatcal1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListQualCat.Contains(quatcal1))
                        {
                            mdb.QualificationCategory.InsertOnSubmit(quatcal1);
                            ListQualCat.Add(quatcal1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(QualificationCategory other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
